package com.ptswitch.material.util;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.IOUtils;

public class SqlReader {

    private List<String> sqls = new ArrayList<String>();

    public SqlReader(InputStream file) {
        try {
            List<String> lines = IOUtils.readLines(file, "UTF-8");
            StringBuilder sb = new StringBuilder();
            for (String line : lines) {
                if (line.trim().isEmpty()) {
                    if (sb.length() != 0) {
                        sqls.add(sb.toString());
                        sb = new StringBuilder();
                    }
                } else {
                    sb.append(line).append("\r\n");
                }
            }
        } catch (Exception e) {

        }
    }

    public List<String> sqls() {
        return sqls;
    }
}
